package org.xx.armory.spring5.wxwork;

import org.apache.commons.lang3.ArrayUtils;

import java.io.Serializable;
import java.util.Arrays;

import static org.apache.commons.lang3.StringUtils.stripToEmpty;
import static org.xx.armory.commons.Validators.rejectIfBlank;

/**
 * 企业微信用户。
 */
public class WxWorkUser
        implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 唯一ID。
     */
    private final String id;

    /**
     * 姓名。
     */
    private final String name;

    /**
     * 别名。
     */
    private final String alias;

    /**
     * 性别。
     */
    private final int gender;

    /**
     * 注册手机号码。
     */
    private final String mobile;

    /**
     * Email
     */
    private final String email;

    /**
     * 所属的部门ID集合。
     */
    private final String[] departmentIds;

    /**
     * 所属的主部门ID。
     */
    private final String mainDepartmentId;

    /**
     * 职务。
     */
    private final String position;

    /**
     * 头像。
     */
    private final String avatar;

    /**
     * 地址。
     */
    private final String address;

    public WxWorkUser(
            String id,
            String name,
            String alias,
            String mobile,
            String email,
            int gender,
            String[] departmentIds,
            String mainDepartmentId,
            String position,
            String avatar,
            String address
    ) {
        this.id = rejectIfBlank(id, "id").strip();
        this.name = rejectIfBlank(name, "name").strip();
        this.alias = stripToEmpty(alias);
        this.mobile = stripToEmpty(mobile);
        this.email = stripToEmpty(email);
        this.gender = gender;
        this.departmentIds = ArrayUtils.clone(departmentIds);
        this.mainDepartmentId = mainDepartmentId != null ? mainDepartmentId : "";
        this.position = stripToEmpty(position);
        this.address = stripToEmpty(address);
        this.avatar = stripToEmpty(avatar);
    }

    public final String getId() {
        return this.id;
    }

    public final String getName() {
        return this.name;
    }

    public final String getAlias() {
        return this.alias;
    }

    public final String getMobile() {
        return this.mobile;
    }

    public final int getGender() {
        return this.gender;
    }

    public final String[] getDepartmentIds() {
        return ArrayUtils.clone(this.departmentIds);
    }

    public final String getMainDepartmentId() {
        return this.mainDepartmentId;
    }

    public final String getPosition() {
        return this.position;
    }

    public final String getAddress() {
        return this.address;
    }

    public final String getAvatar() {
        return this.avatar;
    }

    @Override
    public String toString() {
        return "WxWorkUser("
                + "id=" + this.id + ","
                + "name=" + this.name + ","
                + "alias=" + this.alias + ","
                + "mobile=" + this.mobile + ","
                + "email=" + this.email + ","
                + "department-ids=" + Arrays.toString(this.departmentIds) + ","
                + "main-department-id=" + this.mainDepartmentId + ","
                + "position=" + this.position + ","
                + "address=" + this.address + ","
                + "avatar=" + this.avatar
                + ")@" + Integer.toHexString(System.identityHashCode(this));
    }
}
